/**
 * 凭证列表返回数据项
 */
interface credentialListItemResponse{
    /**
     * 主键
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * app主键
     */
    appKey: string;
    /**
     * app密钥
     */
    appSecrect: string;
}

/**
 * 凭证服务
 */
interface ICredentialService{
    /**
     * 获取列表
     */
    getList(skip: number,count: number):ng.IHttpPromise<ListResponse<credentialListItemResponse>>;
    /**
     * 添加
     * @param appKey app主键
     * @param appSecrect app密钥
     */
    add(appKey:string, appSecrect: string): ng.IHttpPromise<BaseResponse>;
    /**
     * 删除
     * @param id 编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;
    
}

class credentialService implements ICredentialService{
    constructor(private http: ng.IHttpService,private route: routeService){
    }

    getList(skip:number,count:number):ng.IHttpPromise<ListResponse<credentialListItemResponse>>{
        return this.http<ListResponse<credentialListItemResponse>>({
            method:"GET",
            url:this.route.getUrl("credentials?skip={{skip}}&count={{count}}",{
                skip: skip,
                count: count
            })
        });
    }

    add(appKey:string, appSecrect: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("credentials"),
            data: {
                appKey: appKey,
                appSecrect: appSecrect,
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("credentials/{{id}}", {
                id: id
            })
        });
    }
}

app.service("credentialService",["$http",'routeService',credentialService]);